package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {
    /**
     * 判断是类管理是否关联了其他的菜品
     * @param id
     * @return
     */
    @Select("select  count(id) from dish where category_id=#{categoryId}")
    int countDishId(Long id);

    /**
     * 新增菜品，先要关联主键id
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true ,keyProperty = "id")//获取主键值给id
    @Insert("insert into dish value (null,#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser}) ")
    void add(Dish dish);

    Page<DishVO> select(DishPageQueryDTO dishPageQueryDTO);

    @Select("select *from dish where id=#{id}")
    Dish selectById(Long id);

    void deleteDish(List<Long> ids);

    @AutoFill(OperationType.UPDATE)
    void updateDish(Dish dish);
@Update("update dish set status=#{status} where id=#{id}")
    void updateStatus(Dish dish);

@Select("select *from dish where category_id=#{categoryId}")
    List<Dish> selectByCategoryId(Long categoryId);


    List<Dish> selectList(Dish dish);
}
